<?php $baseUrl = $this->baseUrl(); ?>
<form action="<?php echo $baseUrl; ?>/tarefa" method="get">
    <input type="text" name="st_pesquisa" value="<?php echo $this->st_pesquisa; ?>" />
    <input type="submit" value="Pesquisar">
</form>
<link rel="stylesheet" href="<?php echo $this->baseUrl(); ?>/themes/default/css/tarefas.css" media="screen" />
<div id="menu">
    <div class="accordion">
        <?php if ($this->rowTarefaAtual) : ?>
        <h3>Tarefa Atual</h3>
        <div>
            <a href="<?php echo $baseUrl; ?>/tarefa/tarefa/visualizar/id/<?php echo $this->rowTarefaAtual->id_tarefa; ?>"><?php echo $this->rowTarefaAtual->id_tarefa . ' - ' . $this->rowTarefaAtual->st_nome; ?></a>
        </div>
        <?php endif; ?>

        <h3><a class="menu-projetos" href="<?php echo $baseUrl; ?>/projeto/projeto/">Projetos <span class="num"><?php echo count($this->rowSetProjeto); ?></span></a></h3>
        <div>
            <a class="ver-todos" href="<?php echo $baseUrl; ?>/projeto/projeto">Ver todos</a>
            <ul>
                <?php foreach ($this->rowSetProjeto as $cliente => $rowProjetos) : ?>
                    <?php
                    $idCliente   = substr($cliente, 0, strpos($cliente, ' - '));
                    $nomeCliente = substr($cliente, strpos($cliente, ' - ')+3);
                    ?>
                    <li>
                        <a class="menu-cliente" href="<?php echo $baseUrl; ?>/corporativo/cliente/visualizar/id/<?php echo $idCliente; ?>">
                           <?php echo $nomeCliente; ?>
                        </a>
                        <ul class="menu-projetos-cliente">
                            <?php foreach($rowProjetos as $rowProjeto){ ?>
                                <li><a class="menu-projetos-link" style="font-size:9px;" href="<?php echo $baseUrl; ?>/projeto/projeto/visualizar/id/<?php echo $rowProjeto->id_projeto; ?>/cs_situacao/A"><?php echo $rowProjeto->st_nome; ?> (<?php echo $rowProjeto->qtTarefas; ?>)</a>
                            <?php }?>
                        </ul>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>

        <h3><a class="menu-historico" href="#">Histórico</a></h3>
        <div>
            <?php if (count($this->rowSetHistoricos)) : ?>
            <a class="ver-todos" href="<?php echo $baseUrl; ?>/index/historico">Ver todos</a>
            <ul class="historico-home">
                <?php foreach ($this->rowSetHistoricos as $rowHistorico) : ?>
                <li>
                   <?php echo $this->gravatar($rowHistorico->st_email, array('img_size' => 32),
                                              array('alt' => $rowHistorico->usuario,
                                                    'title' => $rowHistorico->usuario,
                                                    'style' => 'float:left; margin:0px 10px 10px 0px;')); ?>
                     <span style="font-size:10px;">
                        <?php echo $rowHistorico->st_titulo; ?>
                    </span>
                </li>
                <?php endforeach; ?>
            </ul>
            <?php endif; ?>
        </div>

        <h3><a class="menu-servicos" href="#">Serviços <span class="num"><?php echo count($this->rowSetServico); ?></span></a></h3>
        <ul>
            <?php foreach ($this->aServicos as $rowServico) : ?>
            <li>
                <a style="font-size:9px;" href="<?php echo $baseUrl; ?>/servico/tipo-servico/visualizar/id/<?php echo $rowServico->id_tipo_servico; ?>">
                <?php echo $rowServico->st_nome; ?> (<?php echo $rowServico->qtServicos; ?>)</a>
            </li>
            <?php endforeach; ?>
        </ul>

    </div><!-- fim de accordion -->
</div>

<div id="conteudo">
    <div class="lista-tarefas accordion">
            <h3><a>Tarefas (<?php echo count($this->rowSetTarefas); ?>)</a></h3>
            <div>
                <table>
                    <thead>
                        <tr>
                            <th scope="col">Fila</th>
                            <th scope="col">Tarefa</th>
                            <th scope="col">Projeto</th>
                            <th scope="col">Final</th>
                        </tr>
                    </thead>

                    <tbody>
                    <?php
                    $i = 0;
                    $dateAtual = new DateTime(date('Y-m-d'));
                    foreach ($this->rowSetTarefas as $rowTarefa) {
                        $class = ($i++ % 2 == 0) ? '' : ' class="cor"';
                        $dtPrevisaoFim = new DateTime($rowTarefa->dt_previsao_fim);
                        if ($dtPrevisaoFim < $dateAtual) {
                            $class = ' class="tarefa-atrasada"';
                        } elseif ($dateAtual == $dtPrevisaoFim) {
                            $class = ' class="tarefa-alerta"';
                        }
                    ?>
                        <tr<?php echo $class; ?>>
                            <td><?php echo $rowTarefa->nr_fila_usuario; ?></td>
                            <td><a href="<?php echo $baseUrl; ?>/tarefa/tarefa/visualizar/id/<?php echo $rowTarefa->id_tarefa; ?>"><?php echo "[{$rowTarefa->id_tarefa}] " . $rowTarefa->st_nome; ?></a></td>
                            <td><a href="<?php echo $baseUrl; ?>/projeto/projeto/visualizar/id/<?php echo $rowTarefa->fk_projeto; ?>"><?php echo isset($this->aProjetos[$rowTarefa->fk_projeto]) ? $this->aProjetos[$rowTarefa->fk_projeto] : ''; ?></a></td>
                            <td><?php echo $this->dateFormat($rowTarefa->dt_previsao_fim); ?></td>
                        </tr>
                    <?php } ?>
                    </tbody>
                </table>
            </div>

    </div><!-- fim de lista-tarefas -->

    <?php if (count($this->rowSetTarefasResponsabilidade)) : ?>
    <div class="lista-tarefas accordion">
            <h3><a>Tarefas de sua responsabilidade (<?php echo count($this->rowSetTarefasResponsabilidade); ?>)</a></h3>
            <div>
                <table>
                    <thead>
                        <tr>
                            <th scope="col">Tarefa</th>
                            <th scope="col">Usuário</th>
                            <th scope="col">Projeto</th>
                            <th scope="col">Final</th>
                        </tr>
                    </thead>

                    <tbody>
                    <?php
                    $i = 0;
                    $dateAtual = new DateTime(date('Y-m-d'));
                    foreach ($this->rowSetTarefasResponsabilidade as $rowTarefa) {
                        $class = ($i++ % 2 == 0) ? '' : ' class="cor"';
                        $dtPrevisaoFim = new DateTime($rowTarefa->dt_previsao_fim);
                        if ($dtPrevisaoFim < $dateAtual) {
                            $class = ' class="tarefa-atrasada"';
                        } elseif ($dateAtual == $dtPrevisaoFim) {
                            $class = ' class="tarefa-alerta"';
                        }
                    ?>
                        <tr<?php echo $class; ?>>
                            <td><a href="<?php echo $baseUrl; ?>/tarefa/tarefa/visualizar/id/<?php echo $rowTarefa->id_tarefa; ?>"><?php echo "[{$rowTarefa->id_tarefa}] " . $rowTarefa->st_nome; ?></a></td>
                            <td><?php echo $this->aUsuarios[$rowTarefa->fk_usuario]; ?></td>
                            <td><a href="<?php echo $baseUrl; ?>/projeto/projeto/visualizar/id/<?php echo $rowTarefa->fk_projeto; ?>"><?php echo isset($this->aProjetos[$rowTarefa->fk_projeto]) ? $this->aProjetos[$rowTarefa->fk_projeto] : ''; ?></a></td>
                            <td><?php echo $this->dateFormat($rowTarefa->dt_previsao_fim); ?></td>
                        </tr>
                    <?php } ?>
                    </tbody>
                </table>
            </div>
    </div><!-- fim de lista-tarefas -->
    <?php endif; ?>
</div>
